﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CtrLayer;
using ModelLayer;
using WCFLayer;
using System.Threading;
using System.Diagnostics;

namespace ConsoleTestingApplication
{
    class Program
    {
        private static List<Airport> mylist;


        static void Main(string[] args)
        {

            AirlineCtr airlineCtr = new AirlineCtr();
            PersonCtr personCtr = new PersonCtr();
            BookingCtr bookingCtr = new BookingCtr();
            PlaneCtr planeCtr = new PlaneCtr();
            Dijkstra dijkstra = new Dijkstra();
            Console.WriteLine("TEST Projekt");

            #region Airport
            /*
            System.Console.WriteLine("Airport test");
            Console.WriteLine("Find possibilities");
            Airport temp = airlineCtr.FindAirportByCode("AAL");
            List<Airport> tempList = airlineCtr.PossibleAirports(temp);
            foreach (var airport in tempList)
            {
                Console.WriteLine(airport.AirportCode);
            }
            Console.ReadKey();
            Console.WriteLine("\nInsert airport");
            Airport insertAirport = new Airport();
            insertAirport.AirportCode = "TIS";
            insertAirport.AirportName = "name";
            insertAirport.City = "city";
            insertAirport.Country = "Country";
            if (airlineCtr.InsertAirport(insertAirport) == 1)
            {
                Console.WriteLine("Insert succes");
            }
            else {
                Console.WriteLine("Insert failed");
            }
            Console.ReadLine();

            System.Console.WriteLine("\nFind by airport code 'PEK'");
            Airport temAirport = new Airport();
            temAirport = airlineCtr.FindAirportByCode("PEK");
            System.Console.WriteLine(temAirport.ToString());
            System.Console.WriteLine("\nSelect all methode afprøves? tryk retur");
            System.Console.ReadLine();

            List<Airport> airportList = new List<Airport>();
            airportList = airlineCtr.SelectAllAirports();
            System.Console.WriteLine(airportList.Count());
            System.Console.WriteLine("\ntryk retur for tostring");
            Console.ReadLine();

            foreach (Airport ap in airportList)
            {
                System.Console.WriteLine(ap.ToString());
            }

            Console.WriteLine("\nRemove Airport");
            if (airlineCtr.RemoveAirport(insertAirport) == 1)
            {
                Console.WriteLine("Remove succes");
            }
            else
            {
                Console.WriteLine("Remove failed");
            }
            Console.ReadLine();

            Console.WriteLine("LUK?");
            Console.ReadLine();
            */
            #endregion
            #region Flight
            /*
            System.Console.WriteLine("\nFlight test");
             System.Console.WriteLine("Find test first by id");

             Flight temFlight = new Flight();
             temFlight = airlineCtr.FindFlightByID(7);
            System.Console.WriteLine("\n" + temFlight.ToString());

            System.Console.ReadLine();

            System.Console.WriteLine("\nselect all metode afprøves");
            List<Flight> flightList = new List<Flight>();

            flightList = airlineCtr.SelectAllFlights();

            System.Console.WriteLine("\nlist count");
            System.Console.WriteLine(flightList.Count());
            System.Console.WriteLine("\n\n");

            foreach (Flight f in flightList)
            {
                System.Console.WriteLine(f.ToString());
            }
            System.Console.WriteLine("\nLUK");
            System.Console.ReadLine();
            */

            #endregion
            #region Flight Instance
            /*
            System.Console.WriteLine("\nFLIGHT INSTANCE TEST");

            #region find
            
            FlightInstance flightInstance = new FlightInstance();
            flightInstance = bookingCtr.FindFlightInstanceById(5);

            Console.WriteLine("Find Instance by ID");
            System.Console.WriteLine(flightInstance.ToString());

            Console.WriteLine("Find Instance by flight and date");
            
            System.Console.ReadLine();
            #endregion 
            
            List<FlightInstance> flightList1 = new List<FlightInstance>();

            flightList1 = bookingCtr.SelectAllFlightInstances();

            foreach (FlightInstance fi in flightList1)
            {
               System.Console.WriteLine(fi.ToString());
            }
            
            Console.WriteLine("Terminate program?");
            Console.ReadKey();
            */
            #endregion
            #region Person
            /*
            System.Console.WriteLine("\nPerson Test");
            System.Console.WriteLine("\n\nFind by PhoneNo");
            Customer temPerson = new Customer();

            //88888888 = Customer Lars Sander 
            temPerson = personCtr.FindCustomerByPhoneNumber(88888888);
            System.Console.WriteLine(temPerson.ToString());
            System.Console.ReadLine();
            
            System.Console.WriteLine("\n\nSelect All metode afprøves");
            List<Customer> plist = new List<Customer>();

            plist = personCtr.SelectAll();

            System.Console.WriteLine("\nCount på PersonList");
            
            System.Console.WriteLine(plist.Count());

            foreach (Customer customer in plist)
            {
                System.Console.WriteLine("\n" + customer.ToString());
            }
            System.Console.WriteLine("\nLUK");
            System.Console.ReadLine();
            */
            #endregion
            #region Plane
            /*
            
            System.Console.WriteLine("\nFind Plane");
            Plane temPlane = new Plane();
            temPlane = planeCtr.FindPlaneByPlaneNo("4");


            System.Console.WriteLine(temPlane.ToString());
            Console.ReadLine();
            System.Console.WriteLine("\n*****************************");

            List<Plane> planeList = planeCtr.SelectAllPlanes();


            Console.ReadLine();

            foreach (Plane p in planeList)
            {
               
                System.Console.WriteLine("Plane no: " + p.PlaneNo + " Planetype: " + p.PlaneType);
            }
            Console.WriteLine(planeList.Count);
            System.Console.ReadLine();
             */
            #endregion
            #region Seatbooking
            /*
            List<SeatBooking> bList = new List<SeatBooking>();
            
            bList = bookingCtr.SelectAllSeatBookings();
            System.Console.WriteLine("\n" + bList.Count + "\n");
            System.Console.WriteLine("\nLIST TEST ");
            System.Console.ReadLine();

            System.Console.WriteLine("\nLIST count ");
            System.Console.WriteLine("\n" + bList.Count + "\n");
            foreach (SeatBooking sb in bList)
            {
                //System.Console.WriteLine("\nSeatNo = " + sb.seatNo + " TravelId = " + sb.travelId);
                Console.WriteLine("\nID: " + sb.SeatBookingId);
                Console.WriteLine("InstanceID: " + sb.FlightInstance.FlightInstanceId);
                Console.WriteLine("SeatNo: " + sb.Seat.SeatNo);
                Console.WriteLine("Checkin: " + sb.CheckedIn);
                Console.WriteLine("TravelId: " + sb.TravelId);
                Console.WriteLine("PlaneNo: " + sb.FlightInstance.Plane.PlaneNo);
            }
            System.Console.ReadLine();
            */
            #endregion
            #region Seat Test
            /*
            string a = "1A";
            string b = "1";

            Seat temSeat = planeCtr.FindSeatBySeatNoAndPlaneNo(a, b);

            System.Console.WriteLine("\n" +temSeat.SeatNo + " AND PLANENO " + temSeat.PlaneNo);
            System.Console.ReadLine();

            System.Console.WriteLine("\nLIST TEST ");
            System.Console.ReadLine();
            List<Seat> seatlist = new List<Seat>();

            seatlist = planeCtr.SelectAllSeats();

            System.Console.WriteLine(seatlist.Count);
       
            foreach (Seat tSeat in seatlist)
            {
                System.Console.WriteLine(tSeat.SeatNo);
            }
            System.Console.ReadLine();
            */
            #endregion
            #region Travel
                 
            Console.WriteLine("\nTravel test");
            Console.WriteLine("Insert test");
            Travel temp = new Travel();
            temp.EndDestination = airlineCtr.FindAirportByCode("AES");
            temp.StartDestination = airlineCtr.FindAirportByCode("EIN");
            temp.Persons.Add(personCtr.FindCustomerByPhoneNumber(88888888));
            FlightInstance tflightinstace =bookingCtr.FindFlightInstanceById(1);
            Seat tSeat = planeCtr.FindSeatBySeatNoAndPlaneNo("1A", "5");
            temp.SeatBooks.Add(bookingCtr.FindSeatBookingByFlightAndSeat(tflightinstace, tSeat));
            bookingCtr.InsertTravel(temp);
            Console.ReadLine();

            Console.WriteLine("find by travel id");
            Travel temtravel = new Travel();
            temtravel = bookingCtr.FindTravel(2);
            Console.WriteLine(temtravel.ToString());
            Console.ReadLine();
            Console.WriteLine("\n\nselect all metode testes");
            List<Travel> travellist = new List<Travel>();

            travellist = bookingCtr.SelectAllTravels();

            Console.WriteLine("count prøves:");
           Console.WriteLine(travellist.Count);
            Console.ReadLine();
            foreach (Travel t in travellist)
            {
                Console.WriteLine(t.ToString());
            }
            Console.WriteLine("luk");
            Console.ReadLine();
            
            
            #endregion
            #region Dijkstra
            /*
            System.Console.WriteLine("\nDijkstra test");
            System.Console.WriteLine("find by travel from ARN to JFK");
            Airport start = airlineCtr.FindAirportByCode("ARN");
            Airport end = airlineCtr.FindAirportByCode("JFK");

            Vertex startVertex = new Vertex();
            startVertex.Self = start;

            Vertex endVertex = new Vertex();
            endVertex.Self = end;

            DateTime flyDate = new DateTime(2013, 1, 1);
            //dijkstra.test(start, flyDate);
            Console.ReadLine();

            Console.WriteLine("Begin Dijkstra search for cheapest price?");
            Console.ReadLine();
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            if (dijkstra.GetCheapestRoute(start, end, flyDate).Count != 0)
            {
                Console.WriteLine("Search results: " + dijkstra.GetCheapestRoute(start, end, flyDate).Count);
                foreach (FlightInstance instance in dijkstra.GetCheapestRoute(start, end, flyDate))
                {
                    Console.WriteLine("\n" + instance.ToString());
                }
            }
            stopWatch.Stop();
            double duration = stopWatch.Elapsed.TotalSeconds;
            Console.WriteLine("\n#########################\nTotal time elapsed: " + duration);
            

            Console.WriteLine("Begin Dijkstra search for fastest travel?");
            Console.ReadLine();
            if (dijkstra.GetQuickestRoute(start, end, flyDate).Count != 0)
            {
                Console.WriteLine("Search results: " + dijkstra.GetQuickestRoute(start, end, flyDate).Count);
                foreach (FlightInstance instance in dijkstra.GetQuickestRoute(start, end, flyDate))
                {
                    Console.WriteLine("\n" + instance.ToString());
                }
            }
             
            Console.WriteLine("Terminate program?");
            Console.ReadLine();
            */
            #endregion    
            #region System Stress test
            /*
            System.Console.Write("System Stress testing");
            System.Console.Write("Starting 9001 threads");
            System.Console.Write("");

            mylist = new List<Airport>();

            int noOfThreads = 9001;
            Thread[] threads = new Thread[noOfThreads];
            List<Thread> tList = new List<Thread>();


            for (int i = 0; i < noOfThreads; i++)
            {
                threads[i] = new Thread(findAirport);
                threads[i].Start();
                tList.Add(threads[i]);
                Console.WriteLine("Tråd: " + i);
            }
            Console.WriteLine("Success!");
            Console.WriteLine("Total number of threads achieved: " + tList.Count);
            Console.WriteLine("\nTerminate program?");
            Console.ReadLine();
            */
            #endregion
            #region GenerateTestData
            /*
            System.Console.Write("TestData");
            Console.WriteLine("\nAwait for datatransaction  to be completed");
            
            int tests = 100;
            for(int i = 0; i < tests; i++ ){
                bookingCtr.gTest();
            }
            Console.WriteLine("\nInsert done, terminate?");
            Console.ReadLine();
            */
            #endregion
            
        }
        static void findAirport()
        {
            WCFLayer.FlightRouteService client = new FlightRouteService();
            Airport t = client.FindAirportByCode("AAL");

        }

    }
   
}
